<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_PLATFORM') or die;

class JFormFieldToken extends JFormField {

    protected $type = 'Token';

    protected function getInput() {
        // Initialize some field attributes.
        $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
        $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';

        // Initialize JavaScript field attributes.
        $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
        $sToken = time();
        return '<span>' . (empty($this->value) ? $sToken : $this->value) . '</span><input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="'
                . htmlspecialchars((empty($this->value) ? $sToken : $this->value), ENT_COMPAT, 'UTF-8') . '"' . $class . $disabled . $onchange . ' />';
    }

}
